import type { Module } from 'vuex'
import type { rootStateType } from '@/store'

export interface systemStateType {
  token: string | null
}

const systemModule: Module<systemStateType, rootStateType> = {
  namespaced: true,
  state: () => ({
    token: uni.getStorageSync('token') || null,
  }),
  mutations: {
    setToken(state, val) {
      state.token = val
      // localStorage.setItem('token', val || null) // 持久化
      uni.setStorageSync('token', val || null)
    },
    removeToken(state) {
      state.token = ''
      uni.removeStorageSync('token')
    },
  },
}

export default systemModule
